package com.example.administrator.yuejian35.Club.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.administrator.yuejian35.Club.adapter.CourseListAdapter;
import com.example.administrator.yuejian35.Club.bean.Course;
import com.example.administrator.yuejian35.Club.model.ClubModel;
import com.example.administrator.yuejian35.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class CourseListActivity extends AppCompatActivity {
    private RecyclerView course_rv;
    private List<Course> list;
    private ImageView ic_back;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_list);
        course_rv= (RecyclerView) findViewById(R.id.course_rv);
        ic_back= (ImageView) findViewById(R.id.video_pic);

        ic_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        final String clubId = getIntent().getStringExtra("clubid");
        ClubModel clubmodel = new ClubModel();
        Call call = clubmodel.getcoursebyclub(clubId);
        call.enqueue(new Callback<List<Course>>() {
            @Override
            public void onResponse(Call<List<Course>> call, Response<List<Course>> response) {

                if(CourseListActivity.this!=null) {
                    list = response.body();
                    CourseListAdapter adapter = new CourseListAdapter(CourseListActivity.this, list);
                    LinearLayoutManager layoutManager = new LinearLayoutManager(CourseListActivity.this);
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);//Horizontal
                    course_rv.setLayoutManager(layoutManager);
                    course_rv.setAdapter(adapter);
                    course_rv.setItemAnimator(new DefaultItemAnimator());
                }
            }

            @Override
            public void onFailure(Call<List<Course>> call, Throwable t) {

            }
        });
    }
}
